<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!doctype html>
<html>
<jsp:include page="../common/import.jsp" flush="true"></jsp:include>

<body>

<jsp:include page="../common/header.jsp" flush="true"></jsp:include>

<div class="main p20">
	<div class="container clear">
        <ul class="left-nav fl pt20 w200">
        <c:if test="${parentId==0}">
            <li><a href="${base}/agent/agent/agentList.xhtml"><span class="iconfont">&#xf014b;</span>代理商</a></li>
        </c:if>
        <c:if test="${parentId==1}">
       		 <li><a href="${base}/agent/agent/agentList.xhtml"><span class="iconfont">&#xf014b;</span>代理商</a></li>
        </c:if>
            <li><a class="ahover" href="${base}/agent/sales/salesList.xhtml"><span class="iconfont">&#xf014d;</span>业务员</a></li>
	        <li><a href="${base}/agent/merchant/merchantList.xhtml"><span class="iconfont">&#xf014b;</span>商户</a></li>
        </ul>
        
        <div class="main-right fr">
        	<div class="b m20 b-radius">
            	<div class="clear bgf5 bb">
                	<h2 class="fl h30 lg30 p5 pl10">新增业务员</h2>
                    <a href="javascript:" class="fr h20 p5 m5 w50 bg1eb9ef cfff b-radius tc" onclick="back()">返回</a>
                </div>
                
                <div class="p10 mt20">
                	<p class="bb c1eb9ef">基本信息&#10043;为必填项</p>
                   <%--  <form action="${pageContext.request.contextPath}/sales/insert.xhtml?" method="POST" onsubmit="return validate();"> --%>
                    <input name="parentId" value="${parentId}" hidden="true">
                    <div class="clear mt20">
                    	<span class="fl w200 tr fb h20 lg20 p5"><span class="ce60012">&#10043;</span>姓名：</span>
                        <input name="name" class="fl w400 h20 p5 b-radius" type="text">
                    </div>
                    
                    <div class="clear mt20">
                    	<span class="fl w200 tr fb h20 lg20 p5"><span class="ce60012">&#10043;</span>手机号：</span>
                        <input name="phone" class="fl w400 h20 p5 b-radius" type="text">
                        <span class="fl w200 tl f12 h20 lg20 p5 ce60012">&#10043;手机号码为作业app的登录账号</span>
                    </div>
                    
                    <div class="clear mt20">
                    	<span class="fl w200 tr fb h20 lg20 p5">职位：</span>
                        <input name="job" class="fl w400 h20 p5 b-radius" type="text">
                    </div>
                    
                    <div class="clear mt20">
                    	<span class="fl w200 tr fb h20 lg20 p5">工号：</span>
                        <input name="jobNum" class="fl w400 h20 p5 b-radius" type="text" placeholder="工号由系统自动分配"readonly="readonly">
                    </div>

                    <div class="tc p50">
                    	<button class="w100 bga0 h20 p10 b-radius" onclick="back()">取消</button>
                        <button class="w100 bgac1 cfff h20 p10 ml30 b-radius"  onclick="submit()">保存</button>
                    </div>
                   <!--  </form> -->
                </div>
                
            </div>
        </div>
    </div>
</div>

<jsp:include page="../common/footer.jsp" flush="true"></jsp:include>
<script type="text/javascript">

function submit(){
	var parentId=document.getElementsByName("parentId")[0].value;
	var name=document.getElementsByName("name")[0].value;
	var phone=document.getElementsByName("phone")[0].value;
	var job=document.getElementsByName("job")[0].value;
	var jobNum=document.getElementsByName("jobNum")[0].value;
	if(name==''||name==null){
		alert("姓名不能为空");
		return ;
	}

	var mobile= phone;
	if(mobile.length==0)
    {
       alert('请输入手机号码！');
       //document.form1.mobile.focus();
       return ;
    }    
    if(mobile.length!=11)
    {
        alert('请输入11位有效的手机号码！');
       // document.form1.mobile.focus();
        return ;
    }
    
    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
    if(!myreg.test(mobile))
    {
        alert('请输入有效的手机号码！');
        //document.form1.mobile.focus();
        return ;
    }
    
	var url = "${base}/agent/sales/insert.xhtml";
	var data = {"parentId":parentId,"name":name,"phone":phone,"job":job};
	$.ajax({
        url: url,
        type: "POST",
        data: data,
        dataType: "json",
        success: function (data) {
        	if (data.status=='1') {
				alert(data.info);
				window.location.href="${base}/agent/sales/salesList.xhtml";
			}
        	if(data.status=='0'){
				alert(data.info);
			}
	        //location.reload(true);
        },
        error: function (data) {
            alert('服务端报错，' + data.status);
        }
    });
}
function back(){
	window.location.href="${base}/agent/sales/salesList.xhtml";
}
 //校验手机号
 function validatemobile(mobile)
 {
     if(mobile.length==0)
     {
        alert('请输入手机号码！');
        //document.form1.mobile.focus();
        return false;
     }    
     if(mobile.length!=11)
     {
         alert('请输入11位有效的手机号码！');
        // document.form1.mobile.focus();
         return false;
     }
     
     var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
     if(!myreg.test(mobile))
     {
         alert('请输入有效的手机号码！');
         //document.form1.mobile.focus();
         return false;
     }
 }
</script>
</body>
</html>